#!/bin/bash

sum() {
    local sum=0
    for num in "$@"; do
        if ! [[ "$num" =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
            echo "Not valid"
            return 1
        fi
        sum=$(bc -l <<< "$sum + $num")
    done
    echo "The sum is: $(printf "%.2f" "$sum")"
}

numbers=()
echo "Enter your numbers (type 'end' to finish):"
while true; do
    read input
    if [ "$input" == "end" ];
    then
        break
    fi
    numbers+=("$input")
done

sum "${numbers[@]}"
